<?php
require_once ($_SERVER['DOCUMENT_ROOT']. '/fatec-si/utils/MYSQLAdapter.php');

class Authenticator{

	public static function authenticate ($login , $password){		
		session_start();
		$mysql = new MYSQLAdapter($GLOBALS['config']);
		$password_hash = $mysql->geraMD5($password);
		$array = array("login" => $login , "senha" => $password_hash);
		$mysql->select("tb_usuario , tb_tipo_usuario ","login = '$login' AND senha = '$password_hash' AND tb_usuario.id_tipo_usuario = tb_tipo_usuario.id_tipo_usuario");

		$result = $mysql->fetchAll('User');

		if ($result){
			$_SESSION['user']= $result[0];
			return true;
		}else{
			return false;
		}
		session_write_close();
	}

	public static function getUser (){
		session_start();
		$user = isset( $_SESSION['user'])? $_SESSION['user']  : "";
		session_write_close();
		return $user;
	}

};
?>
